package com.hy.remotecontrol;

import com.hyh.command.Command;
import com.hyh.command.NoCammand;

public class RemoteControl {

	Command commands[];
	Command undoCommand;
	boolean isOn;
	
	public RemoteControl() {
		commands = new Command[7];
		for(int i=0;i<7;i++){
			commands[i] = new NoCammand();
		}
	}
	
	public void setCommand(int slot,Command cmd){
		commands[slot]=cmd;
	}
	
	public void onButtonWasPushed(int slot){
		commands[slot].execute();
		undoCommand = commands[slot];
		isOn = true;
	}
	
	public void offButtonWasPushed(int slot){
		commands[slot].undo();
		undoCommand = commands[slot];
		isOn = false;
	}
	
	public void undoButtonWasPushed(){
		if(isOn){
			undoCommand.undo();
		}else{
			undoCommand.execute();
		}
		
	}

}
